package com.gosophia.govDoc.action.queryDoc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.govDoc.common.DocumentJobType;
import com.gosophia.govDoc.common.TurningAction;
import com.gosophia.govDoc.dto.DocumentTaskDTO;
import com.gosophia.govDoc.ws.DocumentQueryWebService;
@Scope("prototype")
@Controller("GetDocProcessDetailAction")
public class GetDocProcessDetailAction extends BaseSupportAction{

	private static final long serialVersionUID = 1502732251423032939L;
	
	@Autowired
	private DocumentQueryWebService documentQueryWebService;
    private String editType;
    private String submitType;
	private Long jobId;

	private DocumentTaskDTO documentTaskDTO;
	@Override
	public String _execute() throws Exception {
		documentTaskDTO = documentQueryWebService.findDocProcessDetail(jobId);
		editType="0,0";
		if("submit".equals(submitType)) {
			return "docFinalizeSubmit";
		}
		if(DocumentJobType.simulate.toString().equals(documentTaskDTO.getJobTypeString())) {
			return "docCreate";
		}
		if(DocumentJobType.approve.toString().equals(documentTaskDTO.getJobTypeString())) {
			if(TurningAction.SUBMIT_NEXT_APPROVAL.toString().equals(documentTaskDTO.getTurningAction())) {
				return "docSubmit";
			}
			if(TurningAction.AGREE_FINALIZE.toString().equals(documentTaskDTO.getTurningAction())) {
				return "docFinalizeSubmit";
			}
			if(TurningAction.SENDBACK.toString().equals(documentTaskDTO.getTurningAction())) {
				return "docSubmit";
			}
		}
		if(DocumentJobType.getBack.toString().equals(documentTaskDTO.getJobTypeString())) {
			return "docSubmit";
		}
		if(DocumentJobType.modify.toString().equals(documentTaskDTO.getJobTypeString())) {
			return "docModify";
		}
		if(DocumentJobType.documentFinalize.toString().equals(documentTaskDTO.getJobTypeString())) {
			return "docFinalize";
		}
		return editType;
		
	}

	public Long getJobId() {
		return jobId;
	}

	public void setJobId(Long jobId) {
		this.jobId = jobId;
	}

	public DocumentTaskDTO getDocumentTaskDTO() {
		return documentTaskDTO;
	}

	public void setDocumentTaskDTO(DocumentTaskDTO documentTaskDTO) {
		this.documentTaskDTO = documentTaskDTO;
	}

    public String getEditType() {
        return editType;
    }

    public void setEditType(String editType) {
        this.editType = editType;
    }

	public String getSubmitType() {
		return submitType;
	}

	public void setSubmitType(String submitType) {
		this.submitType = submitType;
	}
	
    
}
